module example2
  use example1
  use ISO_C_binding

  implicit none
  private
  public :: simulation

  type simulation

    class(pointercf), pointer :: pcf => null()
    type(c_ptr), pointer :: part3d_in
    ! integer :: dim1, dim2
    integer :: dim

  contains

    generic :: go2 => go
    generic :: new => init
    generic :: del => end
    procedure, private :: go
    procedure, private :: init, end
   
  end type simulation

  contains

  subroutine init(this)
    implicit none
    class(simulation), intent(inout) :: this

    allocate(this%pcf)
    allocate(this%part3d_in)
    
    

  end subroutine init

  ! subroutine go(this,part3d_in,dim1, dim2)
  subroutine go(this,part3d_in,dim)
    implicit none
    class(simulation), intent(inout) :: this
    ! integer(c_int), intent(inout) :: dim1, dim2
    integer(c_int), intent(in) :: dim
    type(c_ptr), value, intent(in) :: part3d_in


      call this%new()
      this%part3d_in = part3d_in
      ! this%dim1 = dim1
      ! this%dim2 = dim2
      ! print*,this%dim1,this%dim2
      this%dim = dim
      ! call this%pcf%go1(part3d_in, dim1, dim2)
      call this%pcf%go1(part3d_in, dim)
      call this%del()

  end subroutine go

  subroutine end(this)
    implicit none
    class(simulation), intent(inout) :: this

      if (associated(this%part3d_in)) then
        deallocate(this%part3d_in)
      end if
      if (associated(this%pcf)) then
        deallocate(this%pcf)
      end if
  
  end subroutine end  

end module example2
